/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package metier.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Adrien
 */
@Entity
@Table (name="client")
public class Client implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @NotNull
    @Size(max=60)
    @Column
    private String nom;
    
    @NotNull
    @Size(max=60)
    @Column
    private String prenom;
    
    @NotNull
    @Size(max=60)
    @Column
    private String email;
    
    @NotNull
    @Column
    private String motpasse;
    
    @Column
    private int etat;
    
    @NotNull
    @Size(max=60)
    @Column
    private String ville;
    
    @NotNull
    @Column
    private String salt;
    
    @NotNull
    @Column
    private Integer first_otp;
    
    @NotNull
    @Column
    private Integer last_otp;
    
    public Float getMontant()
    {
        Float montant = 0F;
        for (Compte uncompte : possesseur)
        {
            montant += uncompte.getMontant();
        }
        return montant;
    }
    
    public final static int ACTIVE=0, DESACTIVE = 1;  
    
    @OneToMany(mappedBy="possesseur",fetch=FetchType.EAGER, cascade=CascadeType.ALL)
    private List<Compte> possesseur;
    
    public Client(){
        possesseur = new ArrayList<Compte> ();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getPrenom() {
        return prenom;
    }

    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMotpasse() {
        return motpasse;
    }

    public void setMotpasse(String motpasse) {
        this.motpasse = motpasse;
    }

    public int getEtat() {
        return etat;
    }

    public void setEtat(int etat) {
        this.etat = etat;
    }

    public List<Compte> getPossesseur() {
        return possesseur;
    }

    public String getVille() {
        return ville;
    }

    public void setVille(String ville) {
        this.ville = ville;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public Integer getFirst_otp() {
        return first_otp;
    }

    public void setFirst_otp(Integer first_otp) {
        this.first_otp = first_otp;
    }

    public Integer getLast_otp() {
        return last_otp;
    }

    public void setLast_otp(Integer last_otp) {
        this.last_otp = last_otp;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Client)) {
            return false;
        }
        Client other = (Client) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "metier.entity.client[ id=" + id + " ]";
    }
    
}
